package com.dy.lock.screen.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.dy.lock.screen.dao.SmsAuthCodeDao;
import com.dy.lock.screen.pojo.SmsAuthCodeInfo;
import com.dy.lock.screen.scoket.Head;
import com.dy.lock.screen.service.SmsAuthCodeService;

@Service("smsService")
public class SmsAuthCodeServiceImpl implements SmsAuthCodeService {

	@SuppressWarnings("unused")
	private static final Logger log = Logger
			.getLogger(SmsAuthCodeServiceImpl.class);
	@Resource(name = "smsDao")
	private SmsAuthCodeDao authCodeDao;

	@Override
	public SmsAuthCodeInfo queryByPrimaryKey(String id, Head head) {
		SmsAuthCodeInfo sms = new SmsAuthCodeInfo();
		sms.setId(id);
		SmsAuthCodeInfo info = this.authCodeDao.queryByPrimaryKey(sms);
		return info;
	}

	@Override
	public int save(SmsAuthCodeInfo smsAuthCode, Head head) {
		return this.authCodeDao.insert(smsAuthCode);
	}

	@Override
	public SmsAuthCodeInfo queryByMobileAndCode(String mobile, String authCode,
			Head head) {
		SmsAuthCodeInfo info = new SmsAuthCodeInfo();
		info.setAuthCode(authCode);
		info.setMobile(mobile);
		return this.authCodeDao.queryByMobileAndCode(info);
	}

	@Override
	public List<SmsAuthCodeInfo> queryByMobile(String mobile, Head head) {
		SmsAuthCodeInfo info = new SmsAuthCodeInfo();
		info.setMobile(mobile);
		info.setCreateTime(new Date());
		return this.authCodeDao.queryByMobile(info);
	}

}
